﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Client;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Clientss
{
    public class ClientManagementUpdateHandler : IRequestHandler<ClientManagementUpdateCommand, ResultsDTO>
    {
        private readonly IBateRepository<ClientManagement> clients;
        public ClientManagementUpdateHandler(IBateRepository<ClientManagement> clients)
        {
            this.clients = clients;
        }
        public async Task<ResultsDTO> Handle(ClientManagementUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };
            DapperHelper DapperHelper = new DapperHelper();
            var gh = new ClientManagement();
            var str = "UPDATE clientmanagement SET ClientNo='" + request.ClientNo + "',ClientName='" + request.ClientName + "',ClientAName='" + request.ClientAName + "',ClientEname='" + request.ClientEname + "',ClientTypeId='" + request.ClientTypeId + "',ClientSynopsis='" + request.ClientSynopsis + "',ClientSite='" + request.ClientSite + "',ClientWebsite='" + request.ClientWebsite + "',ClientEmail='" + request.ClientEmail + "',ClientPhone='" + request.ClientPhone + "',ClientLogo='" + request.ClientLogo + "',ClientContact1='" + request.ClientContact1 + "',ClientPhone1='" + request.ClientPhone1 + "',ClientEmail1='" + request.ClientEmail1 + "',ClientContact2='" + request.ClientContact2 + "',ClientPhone2='" + request.ClientPhone2 + "',ClientEmail2='" + request.ClientEmail2 + "',SocialCreditCode='" + request.SocialCreditCode + "',IsVaild='" + request.IsVaild + "',Remark='" + request.Remark + "'WHERE ClientId=" + request.ClientId + "";
            var getnum = clients.Add(str, gh, DapperHelper.MangoMesWrite);
            if (getnum != null)
            {
                list.Code = 1;
            }
            return list;
        }
    }
}
